"use strict";
cc._RF.push(module, '3e381Bi8BxAurNfU1A/nJsl', 'GestureGather');
// resources/scripts/Gesture/GestureGather.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var GestureRecognize_1 = require("./GestureRecognize");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var GestureGather = /** @class */ (function (_super) {
    __extends(GestureGather, _super);
    function GestureGather() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.graphics = null;
        _this.color = cc.Color.RED;
        _this._recordPoints = [];
        return _this;
    }
    Object.defineProperty(GestureGather.prototype, "recordPoints", {
        get: function () {
            return this._recordPoints;
        },
        set: function (value) {
            this._recordPoints = value;
        },
        enumerable: false,
        configurable: true
    });
    GestureGather.prototype.start = function () {
        this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
        this.node.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
        this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
        this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchCancel, this);
    };
    GestureGather.prototype.onTouchStart = function (event) {
        this.recordPoints = [];
        this.graphics.clear();
        this.graphics.strokeColor = this.color;
        this.graphics.moveTo(event.getLocationX(), event.getLocationY());
        this.recordPoints.push(new cc.Vec2(event.getLocationX(), event.getLocationY()));
    };
    GestureGather.prototype.onTouchMove = function (event) {
        this.graphics.lineTo(event.getLocationX(), event.getLocationY());
        this.graphics.stroke(); //绘制线条
        this.recordPoints.push(new cc.Vec2(event.getLocationX(), event.getLocationY()));
    };
    GestureGather.prototype.onTouchEnd = function (event) {
        this.graphics.stroke(); //绘制线条
        this.recordPoints.push(new cc.Vec2(event.getLocationX(), event.getLocationY()));
        this.checkGesture();
    };
    GestureGather.prototype.onTouchCancel = function (event) {
        this.onTouchEnd(event);
    };
    GestureGather.prototype.checkGesture = function () {
        var data = GestureRecognize_1.default.instance.linearInterpolation(this.recordPoints, 10);
        this.graphics.clear();
        this.graphics.strokeColor = cc.Color.WHITE;
        this.graphics.moveTo(data[0].x, data[0].y);
        for (var i = 1; i < data.length; i++) {
            this.graphics.lineTo(data[i].x, data[i].y);
            this.graphics.stroke(); //绘制线条
        }
        var directrList = GestureRecognize_1.default.instance.getDirectList(data);
        console.log("手势方向", directrList);
        var gestureType = GestureRecognize_1.default.instance.matchGesture(directrList);
    };
    __decorate([
        property(cc.Graphics)
    ], GestureGather.prototype, "graphics", void 0);
    __decorate([
        property(cc.Color)
    ], GestureGather.prototype, "color", void 0);
    GestureGather = __decorate([
        ccclass
    ], GestureGather);
    return GestureGather;
}(cc.Component));
exports.default = GestureGather;

cc._RF.pop();